import random

from pythonProject.tools.image import *


class RealmRaidAssets:
        def __init__(self, threshold, area_points, img_path):
                self.threshold = threshold
                self.area_points = area_points
                self.image_path = img_path

MEDALS_5 = RealmRaidAssets(area_points=(235, 211, 871, 315), img_path="res/5.png",threshold=0.8)
MEDALS_4 = RealmRaidAssets(area_points=(235, 211, 871, 315), img_path="res/4.png",threshold=0.8)
MEDALS_3 = RealmRaidAssets(area_points=(235, 211, 871, 315), img_path="res/3.png",threshold=0.8)
MEDALS_2 = RealmRaidAssets(area_points=(235, 211, 871, 315), img_path="res/2.png",threshold=0.8)
MEDALS_1 = RealmRaidAssets(area_points=(235, 211, 871, 315), img_path="res/1.png",threshold=0.8)
MEDALS_0 = RealmRaidAssets(area_points=(235, 211, 871, 315), img_path="res/0.png",threshold=0.8)
PRIZE = RealmRaidAssets(area_points=(235, 211, 871, 315), img_path="res/prize.png",threshold=0.8)
ATTACK = RealmRaidAssets(area_points=(0, 0, 1280, 720), img_path="res/attack.png",threshold=0.8)
READY = RealmRaidAssets(area_points=(0, 0, 1280, 720), img_path="res/ready.png",threshold=0.8)
BACK = RealmRaidAssets(area_points=(0, 0, 1280, 720), img_path="res/back.png",threshold=0.8)
POINT = RealmRaidAssets(area_points=(0, 0, 1280, 720), img_path="res/point.png",threshold=0.8)

S = RealmRaidAssets(area_points=(0, 0, 1280, 720), img_path="res/s.png",threshold=0.8)
M = RealmRaidAssets(area_points=(0, 0, 1280, 720), img_path="res/m.png",threshold=0.8)
L = RealmRaidAssets(area_points=(0, 0, 1280, 720), img_path="res/l.png",threshold=0.8)

Confirm_Again = RealmRaidAssets(area_points=(0, 0, 1280, 720), img_path="res/confirm_again.png",threshold=0.8)
Fight_Again = RealmRaidAssets(area_points=(0, 0, 1280, 720), img_path="res/fight_again.png",threshold=0.8)



Fight_Over = RealmRaidAssets(area_points=(0, 0, 1280, 720), img_path="res/fight_over.png",threshold=0.8)
Fight_Fail = RealmRaidAssets(area_points=(0, 0, 1280, 720), img_path="res/fight_fail.png",threshold=0.8)



Challenge_Ticket_Number = RealmRaidAssets(area_points=(1070, 0, 210, 50), img_path="",threshold=0.8)
Already_Fight_Number = RealmRaidAssets(area_points=(184,570, 200, 80), img_path="res/0.png",threshold=0.8)

CHAPTERS_28 = RealmRaidAssets(area_points=(0, 0, 1280, 720), img_path="res/chapter_28.png",threshold=0.8)
Fight_In = RealmRaidAssets(area_points=(0, 0, 1280, 720), img_path="res/fight_in.png",threshold=0.8)
Fight_Explore = RealmRaidAssets(area_points=(0, 0, 1280, 720), img_path="res/fight_explore.png",threshold=0.8)
Scroll_Fragments_S = RealmRaidAssets(area_points=(0, 0, 1280, 720), img_path="res/scroll_fragments_s.png",threshold=0.8)
Scroll_Fragments_M = RealmRaidAssets(area_points=(0, 0, 1280, 720), img_path="res/scroll_fragments_m.png",threshold=0.8)
Scroll_Fragments_L = RealmRaidAssets(area_points=(0, 0, 1280, 720), img_path="res/scroll_fragments_l.png",threshold=0.8)



def image(params):
    time = 0
    while time <120:
        result = process_image(params.area_points, params.img_path, params.threshold)
        if result is not None:
            return result
        sleep_time = random.uniform(0.5, 1.0)
        time.sleep(sleep_time)
        time += 1
    print("Timeout: Image processing did not complete within the allowed time.")
    return None

def ocr_number(params):
    time = 0
    while time <4:
        result = cropped_img(params.area_points)
        if result is not None:
            return result
        sleep_time = random.uniform(0.5, 1.0)
        time.sleep(sleep_time)
        time += 1
    print("Timeout: Image processing did not complete within the allowed time.")
    return None


def huijuan(params):
    result = process_image(params.area_points, params.img_path, params.threshold)
    if result is not None:
        return result